<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function nickName(name) {
        if (name.length < 3) {
          return name[0] + "*";
        }
        if (name.length > 2) {
          return (
            name[0] +
            new Array(name.length - 2).fill("*").join("*") +
            name[name.length - 1]
          );
        }
      }
      console.log(nickName("蔡强伟"));
    </script>
  </body>
</html>
